home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Guided Tour of Multimedia (Second Edition)
/
The Guided Tour of Multimedia (Second Edition).iso
/
trials
/
director
/
evalcopy
/
director.z
/
WIDGET.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-02
|
16KB
|
505 lines
/*****************************************************************************
Macromedia Widget XObject
Sample code for Director Windows Player 3.1
(c) Copyright 1993 Macromedia
All Rights Reserved
Sample code and XObject documentation prepared by
Patrick Milligan of Oakleaf Designs
Direct your comments to him via AppleLink: OAKLEAF,
Phone: 408-257-1547, or Fax: 408-996-9432
*****************************************************************************/
#include <windows.h>
#include "XObject.h"
/*
------------------------------------------------------------------------------
Method Function Prototypes:
------------------------------------------------------------------------------
*/
short __far __pascal __export LibMain(
HANDLE hndInstance, WORD wDataSeg, WORD cbHeapSize, DWORD ignore);
//DJ20jul93int __export __far __pascal WEP(int nParameter);
long __far __pascal __export _widget_mNew(
LxProcTablePtr xtbl, LxMemHandle hWidget);
long __far __pascal __export _widget_mDispose(
LxProcTablePtr xtbl, LxMemHandle hWidget);
LxMemHandle __far __pascal __export _widget_mName(
LxProcTablePtr xtbl, LxMemHandle hWidget);
long __far __pascal __export _widget_mStatus(
LxProcTablePtr xtbl, LxMemHandle hWidget);
LxMemHandle __far __pascal __export _widget_mError(
long lErrorCode, LxProcTablePtr xtbl, LxMemHandle hWidget);
LxMemHandle __far __pascal __export _widget_mLastError(
LxProcTablePtr xtbl, LxMemHandle hWidget);
long __far __pascal __export _widget_mAdd(
long arg1, long arg2, LxProcTablePtr xtbl, LxMemHandle hWidget);
LxMemHandle __far __pascal __export _widget_mFirst(
LxMemHandle hStrIn, long nChars, LxProcTablePtr xtbl, LxMemHandle hWidget);
long __far __pascal __export _widget_mMul(
long nArgs, LxValuePtr argp, LxProcTablePtr xtbl, LxMemHandle hWidget);
long __far __pascal __export _widget_mGlobals(
LxProcTablePtr xtbl, LxMemHandle hWidget);
long __far __pascal __export _widget_mSymbols(
LxProcTablePtr xtbl, LxMemHandle hWidget);
long __far __pascal __export _widget_mSendPerform(
LxProcTablePtr xtbl, LxMemHandle hWidget);
long __far __pascal __export _widget_mFactory(
LxProcTablePtr xtbl, LxMemHandle hWidget);
/*
------------------------------------------------------------------------------
Constants:
------------------------------------------------------------------------------
*/
#define WIDGET_SUCCESS 0 // Successful return code
#define WIDGET_MEM_ALLOC 1 // Memory allocation error
/*
------------------------------------------------------------------------------
Types:
------------------------------------------------------------------------------
*/
typedef struct
{
LxXObjHeader head; // Required XObject header
LxMemHandle hErrMsg; // Sample instance data: handle
short sJunk; // Sample instance data: short
} WidgetType, FAR *pWidgetType;
/*
------------------------------------------------------------------------------
Variables:
------------------------------------------------------------------------------
*/
long lWidgetError = WIDGET_SUCCESS;
HANDLE hInst;
/*
------------------------------------------------------------------------------
FUNCTION || LibMain()
Windows Entry Procedure for DLLs. Called by LibEntry routine.
------------------------------------------------------------------------------
*/
short __far __pascal __export LibMain(
HANDLE hndInstance, WORD wDataSeg, WORD cbHeapSize, DWORD ignore)
{
if (cbHeapSize != 0)
{
if (! LocalInit( (UINT)wDataSeg, (UINT)NULL, (UINT)cbHeapSize))
{
return (0);
}
}
hInst = hndInstance;
return (1);
}
//DJ20jul93/*
//DJ20jul93------------------------------------------------------------------------------
//DJ20jul93FUNCTION || WEP()
//DJ20jul93
//DJ20jul93Windows Exit Procedure for DLLs.
//DJ20jul93------------------------------------------------------------------------------
//DJ20jul93*/
//DJ20jul93int __export __far __pascal WEP(int nParameter)
//DJ20jul93{
//DJ20jul93 return 1;
//DJ20jul93}
/*
------------------------------------------------------------------------------
Internal Functions:
------------------------------------------------------------------------------
*/
// Log some useful debug info to message window
static void LogMessage( LxProcTablePtr xtbl, const char *format, ...)
{
char buf[250]; // !!@ No error check on size.
wvsprintf( buf, format, ((char *)&format)+sizeof(char *) );
xtbl->showMsg( buf );
}
/*
------------------------------------------------------------------------------
Macros:
------------------------------------------------------------------------------
*/
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mNew
Create a new instance of the Widget XObject. Initialize instance variables.
------------------------------------------------------------------------------
*/
long __far __pascal __export _widget_mNew(
LxProcTablePtr xtbl, LxMemHandle hWidget)
{
pWidgetType pWidget;
lWidgetError = WIDGET_SUCCESS;
if ( xtbl->mem_SetSize(hWidget, (long) sizeof(WidgetType) ) != NULL)
{
// Initialize instance data
pWidget = xtbl->mem_Lock(hWidget);
pWidget->hErrMsg = NULL;
pWidget->sJunk = -1;
xtbl->mem_Unlock(hWidget);
}
else
{
lWidgetError = WIDGET_MEM_ALLOC;
}
return (lWidgetError);
}
/*
-----------------------------------------------------------------------------
FUNCTION || _widget_mDispose
Dispose of a Widget XObject instance. Free instance data (if any).
-----------------------------------------------------------------------------
*/
long __far __pascal __export _widget_mDispose(
LxProcTablePtr xtbl, LxMemHandle hWidget)
{
pWidgetType pWidget;
lWidgetError = WIDGET_SUCCESS;
pWidget = xtbl->mem_Lock(hWidget);
if (pWidget->hErrMsg != NULL)
{
// Dispose of saved error message:
xtbl->mem_Dispose(pWidget->hErrMsg);
}
xtbl->mem_Unlock(hWidget);
xtbl->xobj_Dispose(hWidget);
return (lWidgetError);
}
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mName
Return the name of this XObject (e.g. "Widget")
------------------------------------------------------------------------------
*/
LxMemHandle __far __pascal __export _widget_mName(
LxProcTablePtr xtbl, LxMemHandle hWidget)
{
return (xtbl->string_New("Widget"));
}
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mStatus
Return the integer status code from the last Method call.
------------------------------------------------------------------------------
*/
long __far __pascal __export _widget_mStatus(
LxProcTablePtr xtbl, LxMemHandle hWidget)
{
return (lWidgetError);
}
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mError
Return an error string corresponding to the passed error code.
------------------------------------------------------------------------------
*/
LxMemHandle __far __pascal __export _widget_mError(
long lErrorCode, LxProcTablePtr xtbl, LxMemHandle hWidget)
{
LPSTR pStrMsg;
LxMemHandle hStrMsg;
pWidgetType pWidget;
switch ((short) lErrorCode)
{
case WIDGET_SUCCESS:
pStrMsg = "";
break;
case WIDGET_MEM_ALLOC:
pStrMsg = "Memory allocation failure";
break;
default:
pStrMsg = "Unknown error";
break;
}
hStrMsg = xtbl->string_New(pStrMsg);
// Save a copy of returned string in instance variable
pWidget = xtbl->mem_Lock(hWidget);
pWidget->hErrMsg = xtbl->mem_Clone(hStrMsg);
xtbl->mem_Unlock(hWidget);
return (hStrMsg);
}
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mLastError
Return the last error message string returned by mError.
------------------------------------------------------------------------------
*/
LxMemHandle __far __pascal __export _widget_mLastError(
LxProcTablePtr xtbl, LxMemHandle hWidget)
{
pWidgetType pWidget;
LxMemHandle hStrMsg;
pWidget = xtbl->mem_Lock(hWidget); // Lock Object instance
if (pWidget->hErrMsg != NULL)
{
hStrMsg = xtbl->mem_Clone(pWidget->hErrMsg);
}
else
{
hStrMsg = xtbl->string_New("");
}
xtbl->mem_Unlock(hWidget); // Unlock Object instance
return (hStrMsg);
}
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mAdd
Add two integers (arg1 and arg2) and return the integer result.
------------------------------------------------------------------------------
*/
long __far __pascal __export _widget_mAdd(
long arg1, long arg2, LxProcTablePtr xtbl, LxMemHandle hWidget)
{
return (arg1 + arg2);
}
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mFirst
Return a string containing the first nChars characters of string hStrIn.
------------------------------------------------------------------------------
*/
LxMemHandle __far __pascal __export _widget_mFirst(
LxMemHandle hStrIn, long nChars, LxProcTablePtr xtbl, LxMemHandle hWidget)
{
LPSTR pStrIn;
LxMemHandle hStrOut;
LPSTR pStrOut;
hStrOut = xtbl->mem_New(nChars+1, TRUE); // Zero fill
pStrOut = xtbl->mem_Lock(hStrOut); // Lock handles
pStrIn = xtbl->mem_Lock(hStrIn);
xtbl->mem_Copy(pStrOut, pStrIn, nChars); // Copy substring
xtbl->mem_Unlock(hStrOut); // Unlock handles
xtbl->mem_Unlock(hStrIn);
return (hStrOut);
}
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mMul
Return floating point result (long double) which is the product of the two
passed floating point inputs (f1 and f2). Demonstrates V-type methods.
------------------------------------------------------------------------------
*/
long __far __pascal __export _widget_mMul(
long nArgs, LxValuePtr argp, LxProcTablePtr xtbl, LxMemHandle hWidget)
{
long double f1, f2, f3;
long double** returnFloat;
if (nArgs == 2)
{
if (argp[1].ty == TY_FLOAT)
{
f1 = **(long double**) argp[1].it; // Get first argument
}
else
{
xtbl->showMsg("First argument is not floating point\n");
f1 = 0.0;
}
if (argp[2].ty == TY_FLOAT)
{
f2 = **(long double**) argp[2].it; // Get second argument
}
else
{
xtbl->showMsg("Second argument is not floating point\n");
f2 = 0.0;
}
f3 = f1 * f2;
}
else
{
xtbl->showMsg("Wrong number of arguments\n");
f3 = 0.0;
}
// Allocate memory for long double return value
returnFloat = (long double**) xtbl->mem_New(sizeof(long double), FALSE);
if (returnFloat != NULL)
{
// Setup return value
**returnFloat = f3;
argp[0].ty = TY_FLOAT;
argp[0].it = (long) returnFloat;
}
return (0);
}
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mGlobals
Sample code to Read and Modify global variables
------------------------------------------------------------------------------
*/
long __far __pascal __export _widget_mGlobals(
LxProcTablePtr xtbl, LxMemHandle hWidget)
{
LxMemHandle hdl;
LogMessage( xtbl, "\nTest of Get/Set Lingo Globals.\n" );
hdl = xtbl->GetLingoGlobal( "gTest" );
LogMessage( xtbl, "GetLingoGlobal(gTest)=%s\n", *hdl );
LogMessage( xtbl, "Expected value=<old value>\n");
xtbl->mem_Dispose( hdl );
hdl = xtbl->string_New("<new value>");
xtbl->SetLingoGlobal( "gTest", hdl );
LogMessage( xtbl, "SetLingoGlobal set to <new value>\n");
xtbl->mem_Dispose( hdl );
hdl = xtbl->GetLingoGlobal( "gTest" );
LogMessage( xtbl, "GetLingoGlobal(gTest)=%s\n", *hdl );
LogMessage( xtbl, "Expected value=<new value>\n");
xtbl->mem_Dispose( hdl );
return 0;
}
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mSymbols
Sample code to convert Symbols to IDs and back again.
------------------------------------------------------------------------------
*/
long __far __pascal __export _widget_mSymbols(
LxProcTablePtr xtbl, LxMemHandle hWidget)
{
long id;
char strBuf[256];
LogMessage( xtbl,"\nTest of Symbol <--> ID # Conversion\n" );
id = xtbl->ConvertStrToSymbol( "someSym" );
LogMessage( xtbl,"ConvertStrToSymbol(someSym) = id # %ld\n", id );
xtbl->ConvertSymbolToStr( id, strBuf );
LogMessage( xtbl,"ConvertSymbolToStr(%ld) = %s\n", id, strBuf );
return 0;
}
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mSendPerform
Sample code to illustrate usage of SendPerform callback
------------------------------------------------------------------------------
*/
long __far __pascal __export _widget_mSendPerform(
LxProcTablePtr xtbl, LxMemHandle hWidget)
{
LxValue args[4];
args[1].ty = TY_STRING_PTR;
args[1].it = (long) "mAdd";
args[2].ty = TY_LONGINT;
args[2].it = 2;
args[3].ty = TY_LONGINT;
args[3].it = 3;
// Send "mAdd, 2, 3" message to myself
xtbl->SendPerform( 3, &args[0], hWidget );
LogMessage( xtbl,"\nSend mAdd, 2, 3 message to self.\n" );
LogMessage( xtbl,"Expected Result: Type=4, Value=5\n" );
LogMessage( xtbl,"Actual Result: Type=%d, Value=%ld\n",
args[0].ty, args[0].it );
return 0;
}
/*
------------------------------------------------------------------------------
FUNCTION || _widget_mFactory
Sample code to illustrate usage of FindFactory callback
------------------------------------------------------------------------------
*/
long __far __pascal __export _widget_mFactory(
LxProcTablePtr xtbl, LxMemHandle hWidget)
{
LxMemHandle hdl;
hdl = xtbl->FindFactory( "FileIO" );
// Display object handle address:
LogMessage( xtbl, "\nTest of FindFactory callback. Returned object\n" );
LogMessage( xtbl, "handle for FileIO = %lx\n", hdl );
return 0;
}